package com.gitee.cui.client.builder;

import com.gitee.cui.client.client.ClientSession;
import com.gitee.cui.common.common.bean.msg.ProtoMsg;

/**
 * 基础Builder
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/27 15:16
 **/
public class BaseBuilder {
    protected ProtoMsg.HeadType headType;

    private long seqId;

    private ClientSession session;

    public BaseBuilder (ProtoMsg.HeadType headType, ClientSession session) {
        this.headType = headType;
        this.session = session;
    }

    /**
     * 构架消息基础部分
     * @param seqId 序列id
     * @return 消息
     */
    public ProtoMsg.Message buildCommon(long seqId) {
        this.seqId =  seqId;

        ProtoMsg.Message.Builder mb = ProtoMsg.Message.newBuilder()
                .setType(headType)
                .setSessionId(session.getSessionId())
                .setSequence(seqId);
        return mb.buildPartial();
    }
}
